package com.ccsu.joysport.controller;




import com.ccsu.joysport.entity.student;
import com.ccsu.joysport.service.StuInfoService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import java.util.HashMap;
import java.util.Map;

@RestController
@RequestMapping("/ccsu/user")
public class getStuInfoController {
    @Autowired
    private StuInfoService stuInfoService;

    @GetMapping("/getStuInfo")
    public ResponseEntity<Map<String, String>> getStuInfo(@RequestParam String token) {

        student student = stuInfoService.getStuInfoByToken(token);

        if (student != null) {
            Map<String, String> response = new HashMap<>();
            response.put("studentNumber", student.getStudentNumber());
            response.put("name", student.getName());
            response.put("college", student.getCollege());
            response.put("team", student.getTeam());
            response.put("major", student.getMajor());
            return ResponseEntity.ok(response);
        } else {
            return ResponseEntity.status(HttpStatus.NOT_FOUND).body(null);
        }
    }


}